
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import javax.xml.namespace.QName;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.rpc.client.RPCServiceClient;
import zhj.User;

/**
 * <b>function:</b>复杂类型数据WebService客户端调用代码
 * @author hoojo
 * @createDate 2011-1-13 下午03:36:38
 * @file ComplexTypeServiceClient.java
 * @package com.hoo.service
 * @project Axis2WebService
 * @blog http://blog.csdn.net/IBM_hoojo
 * @email hoojo_@126.com
 * @version 1.0
 */
public class ComplexTypeServiceClient {

	public static void main(String[] args) throws IOException {
		
		RPCServiceClient client = new RPCServiceClient();
		Options options = client.getOptions();
		String address = "http://localhost:8082/axis2/services/ComplexTypeService";
		EndpointReference epr = new EndpointReference(address);
		options.setTo(epr);
		
		QName qname = new QName("http://ws.apache.org/axis2", "upload4Byte");
		String path = System.getProperty("user.dir");
		File file = new File(path + "/WebRoot/index.jsp");
		FileInputStream fis = new FileInputStream(file);
		int len = (int) file.length();
		byte[] b = new byte[len];
		int read = fis.read(b);
		//System.out.println(read + "#" + len + "#" + new String(b));
		fis.close();
		Object[] result = client.invokeBlocking(qname, new Object[] { b, len }, new Class[] { String.class });
		System.out.println("upload:" + result[0]);
		
		qname = new QName("http://ws.apache.org/axis2", "getArray");
		result = client.invokeBlocking(qname, new Object[] { 3 }, new Class[] { int[].class });
		int[] arr = (int[]) result[0];
		for (Integer i : arr) {
			System.out.println("int[] :" + i);
		}
		
		qname = new QName("http://ws.apache.org/axis2", "getTwoArray");
		result = client.invokeBlocking(qname, new Object[] {}, new Class[] { String[][].class });
		String[][] arrStr = (String[][]) result[0];
		for (String[] s : arrStr) {
			for (String str : s) {
				System.out.println("String[][]: " + str);
			}
		}
		
		qname = new QName("http://ws.apache.org/axis2", "getUser");
		result = client.invokeBlocking(qname, new Object[] {}, new Class[] { User.class });
		User user = (User) result[0];
		System.out.println("User: " + user);
	}
}
